package com.acegear.horizon.domain.events;

import com.acegear.horizon.domain.models.constraint.DailyFeedType;
import com.acegear.horizon.domain.models.jpa.AGDailyFeed;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by guoweike on 17/2/22.
 */
public class AGDailyCreateEvent extends BaseEvent {

  private Long dailyId;

  private Long date;

  private String background;

  private boolean state;

  private List<AGDailyItem> agDailyItemArrayList;

  public AGDailyCreateEvent() {
  }

  public AGDailyCreateEvent(Long dailyId, Long date, String background, boolean state,
                            List<AGDailyItem> agDailyItemArrayList) {
    this.dailyId = dailyId;
    this.date = date;
    this.background = background;
    this.state = state;
    this.agDailyItemArrayList = agDailyItemArrayList;
    genEventId();
  }

  public Long getDailyId() {
    return dailyId;
  }

  public void setDailyId(Long dailyId) {
    this.dailyId = dailyId;
  }

  public Long getDate() {
    return date;
  }

  public void setDate(Long date) {
    this.date = date;
  }

  public String getBackground() {
    return background;
  }

  public void setBackground(String background) {
    this.background = background;
  }

  public boolean isState() {
    return state;
  }

  public void setState(boolean state) {
    this.state = state;
  }

  public List<AGDailyFeed> getAgDailyItemArrayList() {
    List<AGDailyFeed> agDailyFeeds = new ArrayList<>();
    agDailyItemArrayList.forEach((aGDailyItem ->
        agDailyFeeds.add(new AGDailyFeed(aGDailyItem.getItemId(), aGDailyItem.getItemType(),
            aGDailyItem.getPosition()))
    ));
    return agDailyFeeds;
  }

  public void setAgDailyItemArrayList(List<AGDailyItem> agDailyItemArrayList) {
    this.agDailyItemArrayList = agDailyItemArrayList;
  }

  @Override
  public String routingKey() {
    return "horizon.domain.aGDaily.new";
  }

}

@JsonIgnoreProperties(ignoreUnknown = true)
class AGDailyItem {

  private Long itemId;

  private DailyFeedType itemType;

  private Integer position;


  public Long getItemId() {
    return itemId;
  }

  public void setItemId(Long itemId) {
    this.itemId = itemId;
  }

  public DailyFeedType getItemType() {
    return itemType;
  }

  public void setItemType(DailyFeedType itemType) {
    this.itemType = itemType;
  }

  public Integer getPosition() {
    return position;
  }

  public void setPosition(Integer position) {
    this.position = position;
  }
}
